//引入模块
var gulp = require('gulp'),		
	livereload = require('gulp-livereload'),//网页自动刷新
	webserver = require('gulp-webserver'),//静态服务器
	less = require('gulp-less'); // LESS编译
var minifyCss = require('gulp-minify-css');
var uglify=require('gulp-uglify') ; //文件压缩模块	
var imagemin=require('gulp-imagemin'); //图片压缩
var pngquant=require('imagemin-pngquant'); //图片压缩
gulp.task('html', () => {
  return gulp.src('src/html/*/*.html') // 指明源文件路径、并进行文件匹配
    .pipe(gulp.dest('dist/html')); // 输出路径
});	
	
//注册任务
gulp.task('webserver', () => {
	gulp.src('./').pipe(webserver({
		livereload:true,
		open:'dist/html/index/index.html'  //文件路径
		//路径已更改
	}));	
});
//处理js压缩
gulp.task('ys',function(){
	return gulp.src('src/js/*/*.js').pipe(uglify({preserveComments:'some'}))
	.pipe(gulp.dest('dist/js'));
});
gulp.task('ninifycss',function(){
	return gulp.src('src/scss/*.css').pipe(minifyCss()).pipe(gulp.dest('dist/scss'))
});
// LESS编译
gulp.task('less', function () {
    gulp.src('src/css/*.less')
        .pipe(less())
        .pipe(gulp.dest('dist/css'));
});
//图片压缩处理
gulp.task('images',function(){
	return gulp.src('src/img/*.{png,jpg,gif,scg}')
	.pipe(imagemin({
		progressive:true,//无损压缩
		svgoPlugins:[{removeViewBox:false}],
		use:[pngquant()]
	}))
	.pipe(gulp.dest('dist/img'));
});
//监听任务
gulp.task('watch',function(){
	gulp.watch('src/html/*/*.html',['html']);
    gulp.watch('src/css/*.less',['less']);
    gulp.watch('src/js/*/*.js',['ys']);
    gulp.watch('src/img/*.{png,jpg,gif,scg}',['images']);
     gulp.watch('src/css/*.css',['ninifycss']);

});

//默认的任务
gulp.task('default',['webserver','html','less','ninifycss','ys','images','watch']);
	